package com.pxxy.app_knowledge;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;

import com.bumptech.glide.Glide;
import com.pxxy.lib_common.base.BaseActivity;
import com.pxxy.security512.R;
import com.youth.banner.Banner;
import com.youth.banner.loader.ImageLoader;

import java.util.ArrayList;
import java.util.List;

public class KnowledgeActivity extends BaseActivity implements View.OnClickListener{
    private Banner banner;
    private List<Integer> images;
    private Button btn_knowledge_fl,btn_knowledge_video,btn_knowledge_tklx,btn_knowledge_zd,btn_knowledge_sc,btn_knowledge_pc;
    private ListView knowledge_lv;
    private String data[] = {"地震知识","火灾知识","自救知识","安全常识","地质灾害","台风知识","洪水知识"};//假数据
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public int initLayout() {
        return R.layout.activity_knowledge;
    }

    @Override
    public void initView() {
        super.initView();
        banner=findViewById(R.id.fragment_knowledge_banner);//找到轮播图的id
        btn_knowledge_fl=findViewById(R.id.fragment_knowledge_fl);//知识分类
        btn_knowledge_video=findViewById(R.id.fragment_knowledge_video);//视频科普
        btn_knowledge_tklx=findViewById(R.id.fragment_knowledge_tklx);//题库练习
        btn_knowledge_zd=findViewById(R.id.fragment_knowledge_zd);//知识竞答
        btn_knowledge_sc=findViewById(R.id.fragment_knowledge_sc);//收藏知识
        btn_knowledge_pc=findViewById(R.id.fragment_knowledge_pc);//知识补充
        knowledge_lv=findViewById(R.id.activity_knowledge_listview);//知识的listview
    }

    @Override
    public void initEvent() {
        super.initEvent();
        /**
         * 轮播图
         */
        //设置图片加载器
        banner.setImageLoader(new MyImageLoader());
        //设置图片数据
        banner.setImages(images);
        //开始轮播
        banner.start();
        //设置点击事件
        btn_knowledge_fl.setOnClickListener(this);//知识分类
        btn_knowledge_video.setOnClickListener(this);//视频科普
        btn_knowledge_tklx.setOnClickListener(this);//题库练习
        btn_knowledge_zd.setOnClickListener(this);//知识竞答
        btn_knowledge_sc.setOnClickListener(this);//收藏知识
        btn_knowledge_pc.setOnClickListener(this);//知识补充
    }

    @Override
    public void initData() {
        super.initData();
        //存放图片
        images = new ArrayList<>();
        images.add(R.drawable.a);
        images.add(R.drawable.b);
        images.add(R.drawable.c);
        images.add(R.drawable.d);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,data);//新建并配置ArrayAapeter
        knowledge_lv.setAdapter(adapter);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.fragment_knowledge_fl:
                break;
            case R.id.fragment_knowledge_video:
                startActivity(new Intent(getApplication(),VideoScienceActivity.class));//点击跳转到视频科普页面
                break;
            case R.id.fragment_knowledge_tklx:
                break;
            case R.id.fragment_knowledge_zd:
                break;
            case R.id.fragment_knowledge_sc:
                startActivity(new Intent(getApplication(),KnowledgeCollectionActivity.class));//点击跳转到收藏知识页面
                break;
            case R.id.fragment_knowledge_pc:
                startActivity(new Intent(getApplication(),KnowledgeSupplementActivity.class));
                break;
        }
    }

    /**
     * 轮播图图片加载类
     */
    class MyImageLoader extends ImageLoader {

        @Override
        public void displayImage(Context context, Object path, ImageView imageView) {
            Glide.with(context).load(path).into(imageView);
        }
    }
}

